package com.augurit.wf.app.doccode.web;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;

import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.common.base.action.ExtCrudActionSupport;
import com.augurit.common.base.extmodel.BasicCombo;
import com.augurit.wf.app.doccode.service.IOaDocCodeService;
import com.augurit.wf.app.doccode.web.form.OaDocCodeForm;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "oa-doc-code.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/wf/app/doccode/oa-doc-code.jsp"),
	@Result(name = CrudActionSupport.INPUT, location = "/wf/app/doccode/oa-doc-code-input.jsp")
})
public class OaDocCodeAction extends  ExtCrudActionSupport<OaDocCodeForm>{

	@Autowired
	private IOaDocCodeService oaDocCodeService;

	private OaDocCodeForm form;
	private Long id;
	private Long[] checkedIds;
	private Page<OaDocCodeForm> page = new Page<OaDocCodeForm>(10);

	private String template;
	
	//根据template生成新编号
	public String createNoByTemplate() throws Exception{
		if(template != null && template.trim().length()>0){
			List<BasicCombo> result = oaDocCodeService.createNoByTemplate(template);
			if(result != null && result.size()>0)
				OaDocCodeAction.extRenderListJson(result, true);
		}
		return null;
	}
	
	//更新记录，将序列加1
	public String updateForAddSeq() throws Exception{
		if(id != null){
			this.oaDocCodeService.updateForAddSeq(id);
			OaDocCodeAction.extRenderSuccess();
		}
		return null;
	}
	
	/**
	 * 分页查询
	 */
	@Override
	public String list() throws Exception {
		oaDocCodeService.search(page, form);
		return SUCCESS;
	}

	/**
	 * 新增或修改
	 */
	@Override
	public String input() throws Exception {
		return INPUT;
	}

	/**
	 * 保存新增或者修改的Form对象
	 */
	@Override
	public String save() throws Exception {
		oaDocCodeService.save(form);
		return RELOAD;
	}

	/**
	 * 删除一条记录
	 */
	@Override
	public String delete() throws Exception {
		oaDocCodeService.delete(id);
		return RELOAD;
	}
	
	/**
	 * 删除多条记录
	 */
	public String deleteMore() throws Exception{
		oaDocCodeService.delete(checkedIds);
		return RELOAD;
	}
	
	/**
	 * 准备页面模型
	 */
	@Override
	protected void prepareModel() throws Exception {
		if(id != null){
			form = oaDocCodeService.get(id);
		}
		else
			form = new OaDocCodeForm();
	}
	

	public OaDocCodeForm getModel() {
		return form;
	}
	
	// 属性getter和setter方法
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getCheckedIds() {
		return checkedIds;
	}

	public void setCheckedIds(Long[] checkedIds) {
		this.checkedIds = checkedIds;
	}
	
	public Page<OaDocCodeForm> getPage() {
		return page;
	}


	public void setPage(Page<OaDocCodeForm> page) {
		this.page = page;
	}

	public OaDocCodeForm getForm() {
		return form;
	}

	public void setForm(OaDocCodeForm form) {
		this.form = form;
	}

	public String getTemplate() {
		return template;
	}

	public void setTemplate(String template) {
		this.template = template;
	}
	
	
}
